package com.arajuuri.catinvaders;

import com.arajuuri.catinvaders.fileoperations.Images;
import java.awt.Graphics2D;
import java.util.Iterator;
import java.util.Vector;

/**
 * <p>Title: Cat Invaders</p>
 * <p>Description: A space invaders clone with cats</p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: </p>
 * @author Semi Arajuuri
 * @version 1.0
 */
public class Bullet extends GraphicalObjectAdapter {

    public Bullet() {
        img = images.loadImage("bullet.png");
        hide();
    }

    public Bullet(int x, int y) {
        img = images.loadImage("bullet.png");
        this.x = x;
        this.y = y;
        this.speed = -10;
    }

    public void draw(Graphics2D g2d) {
        g2d.drawImage(img, x, y, null);
    }

    public void move() {
        y += speed;
        if (y < 0) {
            hide();
        }
    }

    public boolean detectCollision(Vector goVector) {
        Iterator iter = goVector.iterator();
        while (iter.hasNext()) {
            GraphicalObject go = (GraphicalObject) iter.next();
            if (go.detectCollision(x + img.getWidth(null) / 2, y)) {
                this.hide();
                return true;
            }
        }
        return false;
    }
}
